import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 3001,
    proxy: {
      '/config': {
        target: 'https://tlafmy.coding.net/api/user/tlafmy/project/afmy/shared-depot/AFMY/git/blob/master/vxconfig/config.json',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/config/, '')
      },
      '/vapi': {
        // target: 'http://backend-api-01.newbee.ltd/api/v1',
        target: 'http://sabre.red:28019/api/v1',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/vapi/, '')
      }
    }
  },
  plugins: [
    vue(),
    Components({ resolvers: [VantResolver()] })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    outDir: 'build-mall', // 生成输出的根目录。如果该目录存在，则会在生成之前将其删除。 默认文件夹名称为dist
    target: 'esnext',
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true, // 生产环境去掉控制台 console
      }
    },
    chunkSizeWarningLimit: 2000, // 调整区块大小警告限制
  }
})
